<?php

/**
 * Framework
 * 
 * Класс работающий с шаблонами (Smarty)
 * 
 * @category   Framework
 * @package    Framework_View
 */

require_once "Framework/Smarty/Smarty.class.php"; // Smarty

class Framework_View
{
    /**
     * Smarty object
     *
     * @var Smarty
     */
    private $_smarty;
    
    /**
     * Framework_View
     *
     */
    public function __construct($base_dir)
    {
        $config = Framework_Registry::get('config');
        //Настройка smarty
        $smarty = new Smarty();
        $smarty->template_dir  = $base_dir;
        $smarty->config_dir    = PATH_ROOT . DIRECTORY_SEPARATOR . $config->smarty->config_dir;
        $smarty->cache_dir     = PATH_ROOT . DIRECTORY_SEPARATOR . $config->smarty->cache_dir;
        $smarty->compile_dir   = PATH_ROOT . DIRECTORY_SEPARATOR . $config->smarty->compile_dir;
        $smarty->compile_check = $config->smarty->compile_check;
        $smarty->caching       = $config->smarty->caching;
        $smarty->debugging     = $config->smarty->debugging;
        $smarty->force_compile = $config->smarty->force_compile;
        
        $this->_smarty = $smarty;
    }
    
    /**
     * Устанавливает переменну в смарти
     *
     * @param string $key
     * @param string $val
     * @return void
     */
    public function __set($key, $val)
    {
        $this->_smarty->assign($key, $val);
    }
    
    /**
     * Вывод
     *
     * @param string $tpl
     * @return void
     */
    public function display($tpl)
    {
        $this->_smarty->display($tpl);
        exit(0);
    }
}
